package com.lineengine.lineengine.utils;

import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

/**
 * PartitionUtil
 *
 * @author wenrong.yu
 */
public class PartitionUtil {
    private PartitionUtil() {
        throw new UnsupportedOperationException();
    }

    public static <P, R> List<R> split(List<P> list, int size, Function<List<P>, List<R>> function) {
        List<R> result = new ArrayList<>();
        Lists.partition(list, size).stream().map(function).forEach(result::addAll);
        return result;
    }
}
